<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSP 'index.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<script type="text/javascript" src="${ctx}/jquery.min.js"></script>
<script type="text/javascript" src="${ctx}/comet4j.js"></script>
<script type="text/javascript">
var count = 0;
window.onload = function(){
    // 建立连接，conn 即web.xml中 CometServlet的<url-pattern>
    JS.Engine.start('${ctx}/conn');
    <%--  
         //保存用户id到session中
         session.setAttribute("currentUserId",user.getId().toString());
    --%>  
    // 监听后台某个频道
    JS.Engine.on(
           { 
            // 对应服务端 “频道1” 的值 msgCount
            msgCount : function(msgCount){
                $("#msgCount").append(msgCount+"<br/>");
            },
            // 对应服务端 “频道2” 的值 msgData
            msgData : function(msgData){
                $("#msgData").append(msgData.用户名 + "," + msgData.金额+"<br/>");
            },
        }
    );
}
</script>
</head>
<body>
消息数量：<span id="msgCount"></span>
消息数据：<span id="msgData"></span>
</body>
</html>